package event;

import java.awt.FlowLayout;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;

public class Example_6_5_JRadioButton_1 extends JFrame {

	private static final long serialVersionUID = 1L;
	public String[] fruitName = {"苹果", "香蕉", "西瓜", "梨"};
	
	public Example_6_5_JRadioButton_1(){
		super("显示单选按钮JRadioButton");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 310, 220);
		this.getContentPane().setLayout(new FlowLayout());
		
		ButtonGroup bg = new ButtonGroup();
		
		for(int i = 0; i<fruitName.length; i++){
			JRadioButton rb = new JRadioButton(fruitName[i]);
			bg.add(rb);
			this.getContentPane().add(rb);
		}
		
		this.setVisible(true);
	}

	public static void main(String[] args) {
		new Example_6_5_JRadioButton_1();
	}
}
